#ifndef LINKCONTROL
#define LINKCONTROL

#include <iostream>
#include "../link/link.h"

#define MAXBITLENGTH 31

class LinkControl
{
  
  Link * North;
  Link * NorthEast;
  Link * NorthWest;
  Link * South;
  Link * SouthEast;
  Link * SouthWest;
  Link * East;
  Link * West;

  unsigned int uint32_HostAddress;
  unsigned int uint32_FinalLabel;
  unsigned int LinkMinShift;
  unsigned int LinkMaxLabel;
  unsigned int uint32_ClockCycle;

  int CompareTwoNumbers(unsigned int valueA, unsigned int valueB);
  void UpdateLinkTargetLabel(Link * LinkA, Link * LinkB);
  void ClockLinks(void);
  void LinkComparisons(void);
  void UpdateLinkListeners(void);

public:
  enum LinkLocation
  {
    NORTH,
    NORTHEAST,
    NORTHWEST,
    SOUTH,
    SOUTHEAST,
    SOUTHWEST,
    EAST,
    WEST,
    NONE
  };

 
  LinkControl(void);
  ~LinkControl(void);

  void SetLinkToNeighbor(LinkLocation location, bool * dataLine);

  void ClockLinkControl(void);

  void PrintLinksBuildLabel(void);

  bool AreAllLinksComplete(void);

  bool * GetPhysicalLinkAddress(LinkLocation location);

  void SetHostAddress(unsigned int hostAddress);

  unsigned int GetLinkControlFinalLabel(void);

  void PrintActiveLinks(void);


private: 
  LinkLocation listener[8];

  LinkLocation CurrentMaxLink;

  LinkLocation LocationList[8];   
 
  void CompareTwoLinksBuildLabels(LinkLocation locationA, LinkLocation locationB);
  Link * GetLink(LinkLocation location);

};




#endif
